import base from './index'
let axios = base.axios
let baseUrl = base.baseUrl

// 获取好友
export const getFriend = params => {
    return axios({
      method: 'get',
      baseURL: `${baseUrl}/friend/friendList`,
      params: {
        data: params
      }
    }).then(res => res.data)
  }

  // 获取聊天信息
  //返回res.data
export const getChatMsg = params => {
  return axios({
    method: 'get',
    baseURL: `${baseUrl}/friend/chatMsg`,
    params: {
      data: params
    }
  }).then(res => res.data)
}

  // 获取聊天信息
  export const chatgpt = params => {
    return axios({
      method: 'get',
      url: 'http://localhost:5000/chat',
      params: params,
      // headers: {
      //   'Content-Type': 'application/json',
      //   // 'Authorization': `Bearer xxxxx`,
      // }
      timeout: 5000
    }).then(res => res.data)
    .catch(error => {
      if (error.code === 'ECONNABORTED') {
        return {
          data: "请求超时"
        }
      } else {
        return {
          data: "请求出错"
        }
      }
      throw error; // 抛出错误以便调用者处理
    });
  }